<?xml version="1.0" encoding="UTF-8"?>
<ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:f="http://java.sun.com/jsf/core"
	xmlns:h="http://java.sun.com/jsf/html" xmlns:p="http://primefaces.org/ui" xmlns:c="http://java.sun.com/jsp/jstl/core"
	xmlns:pe="http://primefaces.org/ui/extensions" template="/WEB-INF/templates/connected.xhtml">
	<ui:define name="content">
		<h:form id="formCompanyGestion">
			<p:tabView id="tab" effect="slide" effectDuration="normal" cache="true" dynamic="true">
				<p:tab id="tabFiche" title="Fiche">
					<h:outputText
						value="The story begins as Don Vito Corleone, the head of a New York Mafia family, oversees his daughter's wedding.   
                    His beloved son Michael has just come home from the war, but does not intend to become part of his father's business. T  
                    hrough Michael's life the nature of the family business becomes clear. The business of the family is just like the head of the family, kind and benevolent to those who give respect,   
                    but given to ruthless violence whenever anything stands against the good of the family." />

				</p:tab>
				<p:tab id="tabProduit" title="Produit">
					<p:dataTable var="produit" value="#{produitController.companyProduits}" lazy="true" paginator="true" paginatorPosition="bottom" rows="10"
						rowsPerPageTemplate="5,10,15" id="produitTable">

						<f:facet name="header">
							<h:outputText value="Liste de vos produits" />
						</f:facet>

						<p:column headerText="Catégorie" sortBy="#{produit.category}" filterBy="#{produit.category}" id="category">
							<h:outputText value="#{produit.category}" />
						</p:column>

						<p:column headerText="Nom" sortBy="#{produit.label}" filterBy="#{produit.label}" id="label">
							<h:outputText value="#{produit.label}" />
						</p:column>

						<p:column headerText="Prix" sortBy="#{produit.prix}" filterBy="#{produit.prix}" id="prix">
							<h:outputText value="#{produit.prix}" />
						</p:column>
					</p:dataTable>
					<p:commandButton value="Ajouter" onclick="addPanel.show();" action="#{produitController.populateTree}" update="addPnl" process="tabProduit" />
					<p:panel id="addPnl" header="Ajout d'un produit" toggleable="true" closable="true" toggleSpeed="500" closeSpeed="500" widgetVar="addPanel"
						visible="false">

						<pe:dynaForm id="dynaForm" value="#{produitController.dynaForm}" var="data">
							<pe:dynaFormControl type="input" for="txt">
								<p:inputText id="txt" value="#{data.value}" required="#{data.required}" />
							</pe:dynaFormControl>
							<pe:dynaFormControl type="calendar" for="cal" styleClass="calendar">
								<p:calendar id="cal" value="#{data.value}" required="#{data.required}" showOn="button" />
							</pe:dynaFormControl>
							<pe:dynaFormControl type="select" for="sel" styleClass="select">
								<p:selectOneMenu id="sel" value="#{data.value}" required="#{data.required}" rendered="#{data.visible}">
									<f:selectItem itemLabel="Select City" itemValue="" />
									<f:selectItems value="#{data.categories}" var="categorie" itemLabel="#{categorie.label}" itemValue="#{categorie.label}" />
									<p:ajax update=":formCompanyGestion:tab:addPnl" listener="#{produitController.gestFilters}" partialSubmit="true" process="sel" />
								</p:selectOneMenu>
							</pe:dynaFormControl>
							<pe:dynaFormControl type="textarea" for="tarea">
								<p:inputTextarea id="tarea" value="#{data.value}" required="#{data.required}" autoResize="false" />
							</pe:dynaFormControl>
							<pe:dynaFormControl type="rating" for="rat">
								<p:rating id="rat" value="#{data.value}" required="#{data.required}" />
							</pe:dynaFormControl>

							<!-- 	<f:facet name="buttonBar">
								<p:commandButton value="Submit" action="#{dynaFormController.submitForm}" process="dynaForm"
									update="_mainForm_dynaFormGroup _mainForm_inputValues" oncomplete="handleComplete(xhr, status, args)" />
								<p:commandButton type="reset" value="Reset" style="margin-left: 5px;" />
							</f:facet>  -->
						</pe:dynaForm>

						<p:treeTable value="#{produitController.rootCateg}" var="node" id="genericTable">
							<f:facet name="header">  
					            Document Viewer  
					        </f:facet>

							<p:column>
								<f:facet name="header">  
					                Name  
					            </f:facet>
								<h:outputText value="#{node.isProduct ? node.produitGenerique.label : node.category.label }" />
							</p:column>


							<p:column style="width:10px;">
								<f:facet name="header">  
					                Ajouter  
					            </f:facet>
								<p:commandLink update=":formCompanyGestion:tab:produitPanel" oncomplete="productDialog.show()" title="Crée le produit" style="margin: auto;"
									styleClass="#{node.isProduct ? 'ui-icon ui-icon-plusthick':''}" action="#{produitController.prepareProduct}" process="@this">
									<f:setPropertyActionListener value="#{node}" target="#{produitController.selectedProduct}" />
								</p:commandLink>
							</p:column>
						</p:treeTable>

					</p:panel>
					<p:dialog id="produitDial" header="Création Produit" showEffect="fade" widgetVar="productDialog" modal="true" resizable="false">
						<p:outputPanel id="produitPanel">
							<h:panelGrid columns="2" cellpadding="5" rendered="#{not empty produitController.selectedProduct}">

								<h:outputLabel for="nameProduit" value="Name: " />
								<p:inputText id="nameProduit" value="#{produitController.companyproduit.label}" style="font-weight:bold" />

								<h:outputLabel for="prix" value="Prix: " />
								<pe:inputNumber id="prix" value="#{produitController.companyproduit.prix}" style="font-weight:bold; text-align:right;" decimalPlaces="2"
									symbol=" €" symbolPosition="rigth" decimalSeparator="." />


								<h:outputLabel for="duree" value="Durée " />
								<p:selectOneMenu id="duree" value="#{produitController.companyproduit.duree}" style="font-weight:bold">
									<f:selectItem itemLabel="5" itemValue="5" />
									<f:selectItem itemLabel="10" itemValue="10" />
									<f:selectItem itemLabel="15" itemValue="15" />
									<f:selectItem itemLabel="20" itemValue="20" />
									<f:selectItem itemLabel="30" itemValue="30" />
									<f:selectItem itemLabel="45" itemValue="45" />
									<f:selectItem itemLabel="60" itemValue="60" />
								</p:selectOneMenu>

								<h:outputLabel for="before" value="Temps avant " />
								<p:selectOneMenu id="before" value="#{produitController.companyproduit.margeAvant}" style="font-weight:bold">
									<f:selectItem itemLabel="0" itemValue="0" />
									<f:selectItem itemLabel="5" itemValue="5" />
									<f:selectItem itemLabel="10" itemValue="10" />
									<f:selectItem itemLabel="15" itemValue="15" />
									<f:selectItem itemLabel="20" itemValue="20" />
									<f:selectItem itemLabel="30" itemValue="30" />
									<f:selectItem itemLabel="45" itemValue="45" />
									<f:selectItem itemLabel="60" itemValue="60" />
								</p:selectOneMenu>

								<h:outputLabel for="after" value="Temps après " />
								<p:selectOneMenu id="after" value="#{produitController.companyproduit.margeApres}" style="font-weight:bold">
									<f:selectItem itemLabel="0" itemValue="0" />
									<f:selectItem itemLabel="5" itemValue="5" />
									<f:selectItem itemLabel="10" itemValue="10" />
									<f:selectItem itemLabel="15" itemValue="15" />
									<f:selectItem itemLabel="20" itemValue="20" />
									<f:selectItem itemLabel="30" itemValue="30" />
									<f:selectItem itemLabel="45" itemValue="45" />
									<f:selectItem itemLabel="60" itemValue="60" />
								</p:selectOneMenu>
								<p:commandButton id="saveProduct" value="Enregistrer" onsuccess="productDialog.hide();addPanel.close();"
									action="#{produitController.createProductCompany}" update="produitTable" process="produitPanel" />
								<p:commandButton id="canselProduct" value="Annuler" onclick="productDialog.hide();" process="@none" />
							</h:panelGrid>
						</p:outputPanel>
					</p:dialog>
				</p:tab>
				<p:tab id="tabPlaning" title="Planing">
					<p:fieldset legend="Gérer les planings" toggleable="true" toggleSpeed="500" id="creatPlaning">
						<p:dataTable id="employeeTable" var="employee" value="#{companyController.employees}">
							<p:column headerText="Nom">
								<h:outputText value="#{employee.lastName}" />
							</p:column>

							<p:column headerText="Prénom">
								<h:outputText value="#{employee.firtName}" />
							</p:column>

							<p:column headerText="Pseudo">
								<h:outputText value="#{employee.pseudo}" />
							</p:column>
							<p:column headerText="Editer">
								<p:commandButton id="btnEdit" value="Editer" icon="ui-icon-pencil" onclick="planingDial.show()"
									action="#{companyController.findEmployeePlaning}" update=":formCompanyGestion:tab:planingGrid" process="@this">
									<f:setPropertyActionListener value="#{employee}" target="#{companyController.userSelected}" />
								</p:commandButton>
							</p:column>
						</p:dataTable>
						<p:dialog id="planingEdit" header="Editer le Planing" dynamic="true" modal="true" resizable="false" showEffect="fade" hideEffect="fade"
							widgetVar="planingDial">
							<p:panelGrid id="planingGrid">
								<f:facet name="header">
									<p:row>
										<p:column colspan="5">Planing</p:column>
									</p:row>
									<p:row>
										<p:column colspan="1"></p:column>
										<p:column colspan="2">Matin</p:column>
										<p:column colspan="2">Après midi</p:column>
									</p:row>
									<p:row>
										<p:column colspan="1"></p:column>
										<p:column colspan="1">Début</p:column>
										<p:column colspan="1">Fin</p:column>
										<p:column colspan="1">Début</p:column>
										<p:column colspan="1">Fin</p:column>
									</p:row>
								</f:facet>
								<p:row>
									<p:column colspan="1">Lundi</p:column>
									<p:column colspan="1">
										<pe:timePicker value="#{companyController.semaine.lunMatDeb}" endHours="13" intervalMinutes="10" />
									</p:column>
									<p:column colspan="1">
										<pe:timePicker value="#{companyController.semaine.lunMatFin}" endHours="13" intervalMinutes="10" />
									</p:column>
									<p:column colspan="1">
										<pe:timePicker value="#{companyController.semaine.lunApDeb}" startHours="13" intervalMinutes="10" />
									</p:column>
									<p:column colspan="1">
										<pe:timePicker value="#{companyController.semaine.lunApFin}" startHours="13" intervalMinutes="10" />
									</p:column>
								</p:row>
								<p:row>
									<p:column colspan="1">Mardi</p:column>
									<p:column colspan="1">
										<pe:timePicker value="#{companyController.semaine.marMatDeb}" endHours="13" intervalMinutes="10" />
									</p:column>
									<p:column colspan="1">
										<pe:timePicker value="#{companyController.semaine.marMatFin}" endHours="13" intervalMinutes="10" />
									</p:column>
									<p:column colspan="1">
										<pe:timePicker value="#{companyController.semaine.marApDeb}" startHours="13" intervalMinutes="10" />
									</p:column>
									<p:column colspan="1">
										<pe:timePicker value="#{companyController.semaine.marApFin}" startHours="13" intervalMinutes="10" />
									</p:column>
								</p:row>
								<p:row>
									<p:column colspan="1">Mercredi</p:column>
									<p:column colspan="1">
										<pe:timePicker value="#{companyController.semaine.merMatDeb}" endHours="13" intervalMinutes="10" />
									</p:column>
									<p:column colspan="1">
										<pe:timePicker value="#{companyController.semaine.merMatFin}" endHours="13" intervalMinutes="10" />
									</p:column>
									<p:column colspan="1">
										<pe:timePicker value="#{companyController.semaine.merApDeb}" startHours="13" intervalMinutes="10" />
									</p:column>
									<p:column colspan="1">
										<pe:timePicker value="#{companyController.semaine.merApFin}" startHours="13" intervalMinutes="10" />
									</p:column>
								</p:row>
								<p:row>
									<p:column colspan="1">Jeudi</p:column>
									<p:column colspan="1">
										<pe:timePicker value="#{companyController.semaine.jeuMatDeb}" endHours="13" intervalMinutes="10" />
									</p:column>
									<p:column colspan="1">
										<pe:timePicker value="#{companyController.semaine.jeuMatFin}" endHours="13" intervalMinutes="10" />
									</p:column>
									<p:column colspan="1">
										<pe:timePicker value="#{companyController.semaine.jeuApDeb}" startHours="13" intervalMinutes="10" />
									</p:column>
									<p:column colspan="1">
										<pe:timePicker value="#{companyController.semaine.jeuApFin}" startHours="13" intervalMinutes="10" />
									</p:column>
								</p:row>
								<p:row>
									<p:column colspan="1">Vendredi</p:column>
									<p:column colspan="1">
										<pe:timePicker value="#{companyController.semaine.venMatDeb}" endHours="13" intervalMinutes="10" />
									</p:column>
									<p:column colspan="1">
										<pe:timePicker value="#{companyController.semaine.venMatFin}" endHours="13" intervalMinutes="10" />
									</p:column>
									<p:column colspan="1">
										<pe:timePicker value="#{companyController.semaine.venApDeb}" startHours="13" intervalMinutes="10" />
									</p:column>
									<p:column colspan="1">
										<pe:timePicker value="#{companyController.semaine.venApFin}" startHours="13" intervalMinutes="10" />
									</p:column>
								</p:row>
								<p:row>
									<p:column colspan="1">Samedi</p:column>
									<p:column colspan="1">
										<pe:timePicker value="#{companyController.semaine.samMatDeb}" endHours="13" intervalMinutes="10" />
									</p:column>
									<p:column colspan="1">
										<pe:timePicker value="#{companyController.semaine.samMatFin}" endHours="13" intervalMinutes="10" />
									</p:column>
									<p:column colspan="1">
										<pe:timePicker value="#{companyController.semaine.samApDeb}" startHours="13" intervalMinutes="10" />
									</p:column>
									<p:column colspan="1">
										<pe:timePicker value="#{companyController.semaine.samApFin}" startHours="13" intervalMinutes="10" />
									</p:column>
								</p:row>
								<p:row>
									<p:column colspan="1">Dimanche</p:column>
									<p:column colspan="1">
										<pe:timePicker value="#{companyController.semaine.dimMatDeb}" endHours="13" intervalMinutes="10" />
									</p:column>
									<p:column colspan="1">
										<pe:timePicker value="#{companyController.semaine.dimMatFin}" endHours="13" intervalMinutes="10" />
									</p:column>
									<p:column colspan="1">
										<pe:timePicker value="#{companyController.semaine.dimApDeb}" startHours="13" intervalMinutes="10" />
									</p:column>
									<p:column colspan="1">
										<pe:timePicker value="#{companyController.semaine.dimApFin}" startHours="13" intervalMinutes="10" />
									</p:column>
								</p:row>
							</p:panelGrid>
							<h:panelGrid columns="2">
								<p:commandButton value="Enregistrer" action="#{companyController.savePlaningStatic}" oncomplete="planingDial.hide()" process="planingGrid" />
								<p:commandButton value="Annuler" onclick="planingDial.hide()" process="@none" />
							</h:panelGrid>
						</p:dialog>

					</p:fieldset>
					<p:fieldset legend="Gérer les exceptions" toggleable="true" toggleSpeed="500" id="exeptionPlaning">
						<p:dataTable id="tableException" var="exception" value="#{companyController.exceptions}" paginator="true" rows="10"
							paginatorTemplate="{RowsPerPageDropdown} {FirstPageLink} {PreviousPageLink} {CurrentPageReport} {NextPageLink} {LastPageLink}"
							rowsPerPageTemplate="5,10,15" selectionMode="single" lazy="true">
							<p:column headerText="Employé" sortBy="#{exception.user}" filterBy="#{exception.user}">
								<h:outputText value="#{exception.user}" />
							</p:column>

							<p:column headerText="Descriptif" sortBy="#{exception.descriptif}" filterBy="#{exception.descriptif}">
								<h:outputText value="#{exception.descriptif}" />
							</p:column>

							<p:column headerText="Début" sortBy="#{exception.dateDebut}" filterBy="#{exception.dateDebut}">
								<h:outputText value="#{exception.dateDebut}" />
							</p:column>

							<p:column headerText="Fin" sortBy="#{exception.dateFin}" filterBy="#{exception.dateFin}">
								<h:outputText value="#{exception.dateFin}" />
							</p:column>
							<p:column>
								<p:commandLink update=":formCompanyGestion:tab:produitPanel" oncomplete="exceptionDial.show()" title="Editer l'exception"
									style="margin: auto;" styleClass="ui-icon ui-icon-pencil" partialSubmit="@this">
									<f:setPropertyActionListener value="#{exception}" target="#{companyController.exceptionPlaningSelected}" />
								</p:commandLink>
							</p:column>
						</p:dataTable>
						<p:commandButton id="btnAddException" value="Ajouter une exception" icon="ui-icon ui-icon-plusthick"
							action="#{companyController.newExceptionPlaning}" update=":formCompanyGestion:tab:exceptionGrid" process="@this" onclick="exceptionDial.show()" />
					</p:fieldset>
					<p:dialog id="exceptionEdit" header="Editer le Planing" dynamic="true" modal="true" resizable="false" showEffect="fade" hideEffect="fade"
						widgetVar="exceptionDial">
						<h:panelGrid id="exceptionGrid" columns="2" cellpadding="5">
							<p:outputLabel id="lblUser" for="selUser" value="Employé : " />
							<p:selectOneMenu id="selUser" value="#{companyController.exceptionPlaningSelected.userid}" required="true"
								requiredMessage="Vous devez sélectionner un Employé.">
								<f:selectItem itemValue="" itemLabel="Sélectionner un employé" />
								<f:selectItems value="#{companyController.employees}" var="employee" itemLabel="#{employee.firtName} #{employee.lastName}"
									itemValue="#{employee}" />
							</p:selectOneMenu>
						</h:panelGrid>
						<h:panelGrid id="exceptionGrid2" columns="3" cellpadding="5">
							<p:outputLabel id="lbldtDebut" for="selUser" value="Début : " />
							<p:calendar id="pickDebut" value="#{companyController.exceptionPlaningSelected.dateDebut}" size="8" />
							<pe:timePicker value="#{companyController.exceptionHeureDeb}" startHours="8" intervalMinutes="10" />
							<p:outputLabel id="lbldtFin" for="selUser" value="Fin : " />
							<p:calendar id="pickFin" value="#{companyController.exceptionPlaningSelected.dateFin}" size="8" />
							<pe:timePicker value="#{companyController.exceptionHeureFin}" startHours="8" intervalMinutes="10" />
						</h:panelGrid>
							<h:panelGroup styleClass="validBtnException">
								<p:commandButton id="btnValideExection" value="Valider" />
								<p:commandButton id="btnAnnuleExection" value="Annuler" />
							</h:panelGroup>
					</p:dialog>
				</p:tab>
			</p:tabView>
		</h:form>
	</ui:define>
</ui:composition>

